package com.efast.dmom.mgmt.controller.mes;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.dmom.mgmt.bean.mes.ProductConfigAcceptBean;
import com.efast.dmom.mgmt.bean.mes.WorkOrderInfoDto;
import com.efast.dmom.mgmt.bean.mes.prodConfig.SopUploadBean;
import com.efast.dmom.mgmt.bean.mes.qm.QMCheckAreaBean;
import com.efast.dmom.mgmt.bean.mes.qm.QMCheckDefectCodeBean;
import com.efast.dmom.mgmt.bean.mes.qm.QMCheckItemBean;
import com.efast.dmom.mgmt.bean.mes.qm.QMCheckPartBean;
import com.efast.dmom.mgmt.entity.mes.TrBasProductConfig;
import com.efast.dmom.mgmt.service.mes.TrBasPdPlRouteService;
import com.efast.dmom.mgmt.service.mes.TrBasProductConfigService;

@Controller
@RequestMapping(value = "/trBasProductConfig")
public class TrBasProductConfigController {
	@Autowired
	private TrBasProductConfigService trBasProductConfigService;
	
	@Autowired
	private TrBasPdPlRouteService trBasPdPlRouteService;
	
	// 通过工序id判断是否可以装箱
	@RequestMapping(value = "/getCfgConfig")
	public @ResponseBody ResultBean getCfgConfig(@RequestBody WorkOrderInfoDto dto) {
		ResultBean result = new ResultBean(true, "'");
		TrBasProductConfig cfg = trBasProductConfigService.getCfgConfig(dto);
		if (cfg != null) {
			result.setObject(cfg);
		} else {
			result.setSuccess(false);
			result.setMessage("");
		}
		return result;
	}

	// 用来标识是否为质量门
	@RequestMapping(value = "/isQualityGate")
	public @ResponseBody ResultBean updateIsQualityGate(@RequestBody Map<String, Object> map) {
		ResultBean resultBean = new ResultBean(true, "执行错误");
		trBasProductConfigService.updateIsQualityGate(map);
		return resultBean;
	}
	
	// 用来标识是否是拉入拉出
	@RequestMapping(value = "/isInAndOut")
	public @ResponseBody ResultBean updateIsInAndOut(@RequestBody Map<String, Object> map) {
		ResultBean resultBean = new ResultBean(true, "执行错误");
		trBasProductConfigService.updateIsInAndOut(map);
		return resultBean;
	}
	
	// 用来标识是否是自动开始
	@RequestMapping(value = "/isAutoStart")
	public @ResponseBody ResultBean updateIsAutoStart(@RequestBody Map<String, Object> map) {
		ResultBean resultBean = new ResultBean(true, "执行错误");
		trBasProductConfigService.updateIsAutoStart(map);
		return resultBean;
	}
	
	// 用来标识是否配置为合格证编号
	@RequestMapping(value = "/isCertificate")
	public @ResponseBody ResultBean updateIsCertificate(@RequestBody Map<String, Object> map) {
		ResultBean resultBean = new ResultBean(true, "执行错误");
		trBasProductConfigService.updateIsCertificate(map);
		return resultBean;
	}
	// 用来标识是否配置为VIN绑定工位
	@RequestMapping(value = "/isVinBinding")
	public @ResponseBody ResultBean updateIsVinBinding(@RequestBody Map<String, Object> map) {
		ResultBean resultBean = new ResultBean(true, "执行错误");
		trBasProductConfigService.updateIsVinBinding(map);
		return resultBean;
	}	
	@RequestMapping(value = "/saveSopAttachment")
	public @ResponseBody ResultBean saveSopAttachment(@RequestBody SopUploadBean sopBean) {
		
		ResultBean resultBean = new ResultBean(true, "保存图片成功");
		trBasProductConfigService.uploadSop(sopBean);
		return resultBean;
	}
	
	@RequestMapping(value = "/selectQualityGate")
	public @ResponseBody ResultBean selectQualityGate(@RequestBody Map<String, Object> map) {
		ResultBean selectQualityGate = trBasProductConfigService.selectQualityGate(map);
		return selectQualityGate;
	}

	// 质量门通过id查询
	@RequestMapping(value = "/selectQualityGateByid")
	public @ResponseBody ResultBean selectQualityGateByid(@RequestBody Map<String, Object> map) {
		ResultBean selectQualityGateByid = trBasProductConfigService.selectQualityGateByid(map);
		return selectQualityGateByid;
	}
	
	//首工位通过id来查询
	@RequestMapping(value = "/selectHeadStationByid")
	public @ResponseBody ResultBean selectHeadStationByid(@RequestBody Map<String, Object> map) {
		ResultBean selectQualityGateByid = trBasProductConfigService.selectHeadStationByid(map);
		return selectQualityGateByid;
	}

	// 通过id判断是否显示缺陷录入
	@RequestMapping(value = "/selectShowDefectSectionGateByid")
	public @ResponseBody ResultBean selectShowDefectSectionGateByid(@RequestBody Map<String, Object> map) {
		ResultBean selectQualityGateByid = trBasProductConfigService.selectShowDefectSectionGateByid(map);
		return selectQualityGateByid;
	}
	
	// 通过id判断是否显示拉入拉出
	@RequestMapping(value = "/selectShowInAndOutSectionGateByid")
	public @ResponseBody ResultBean selectShowInAndOutSectionGateByid(@RequestBody Map<String, Object> map) {
	     ResultBean selectQualityGateByid = trBasProductConfigService.selectShowInAndOutSectionGateByid(map);
		 return selectQualityGateByid;
		}
	
	// 通过id判断是否显示自动开始
		@RequestMapping(value = "/selectIsAutoStartSectionGateByid")
		public @ResponseBody ResultBean selectIsAutoStartSectionGateByid(@RequestBody Map<String, Object> map) {
		 ResultBean selectIsAutoStartSectionGateByid = trBasProductConfigService.selectIsAutoStartSectionGateByid(map);
	     return selectIsAutoStartSectionGateByid;
	    }
		
	 // 通过id判断是否显示合格证编号
	   @RequestMapping(value = "/selectIsCertificateSectionGateByid")
	   public @ResponseBody ResultBean selectIsCertificateSectionGateByid(@RequestBody Map<String, Object> map) {
		 ResultBean selectIsCertificateSectionGateByid = trBasProductConfigService.selectIsCertificateSectionGateByid(map);
	     return selectIsCertificateSectionGateByid;
	    }
		 // 通过id判断是否显示Vin绑定工位
	   @RequestMapping(value = "/selectIsVinBindingSectionGateByid")
	   public @ResponseBody ResultBean selectIsVinBindingSectionGateByid(@RequestBody Map<String, Object> map) {
		 ResultBean selectIsVinBindingSectionGateByid = trBasProductConfigService.selectIsVinBindingSectionGateByid(map);
	     return selectIsVinBindingSectionGateByid;
	    }
	// 改变缺陷录入字段的状态
	@RequestMapping(value = "/updateDefectCodeFlag")
	public @ResponseBody ResultBean updateDefectCodeFlag(@RequestBody Map<String, Object> map) {
		ResultBean resultBean = new ResultBean(true, null);
		trBasProductConfigService.updateDefectCodeFlag(map);
		return resultBean;
	}

	// 查询bomItem表中的所有的零件
	@RequestMapping(value = "/selectAllBomItemPart/{partNoVersion}")
	public @ResponseBody ResultBean selectAllBomItemPart(@PathVariable("partNoVersion") String partNoVersion) {
		ResultBean resultBean = new ResultBean(true, null);
		List<QMCheckPartBean> selectAllBomItemPart = trBasProductConfigService.selectAllBomItemPart(partNoVersion);
		resultBean.setObject(selectAllBomItemPart);
		return resultBean;
	}

	// 查询区域表中的区域名
	@RequestMapping(value = "/selectAllArea")
	public @ResponseBody ResultBean selectAllArea() {
		ResultBean resultBean = new ResultBean(true, null);
		List<QMCheckAreaBean> selectAllArea = trBasProductConfigService.selectAllArea();
		resultBean.setObject(selectAllArea);
		return resultBean;
	}

	// 查询qm_bas_shop_defectcode表中的检测项通过工位
	@RequestMapping(value = "/selectItemfromShop/{stationId}")
	public @ResponseBody ResultBean selectItemfromShop(@PathVariable("stationId") Integer stationId) {
		ResultBean resultBean = new ResultBean(true, null);
		List<QMCheckItemBean> selectItemfromShop = trBasProductConfigService.selectItemfromShop(stationId);
		resultBean.setObject(selectItemfromShop);
		return resultBean;
	}

	// 查询qm_bas_shop_defectcode表中的缺陷代码通过检测项
	@RequestMapping(value = "/selectDefectcodefromItem")
	public @ResponseBody ResultBean selectDefectcodefromItem(@RequestBody Map<String, Object> map) {
		ResultBean resultBean = new ResultBean(true, null);
		List<QMCheckDefectCodeBean> selectItemfromShop = trBasProductConfigService.selectDefectcodefromItem(map);
		resultBean.setObject(selectItemfromShop);
		return resultBean;
	}
	// 多条件查询是否缺陷录入
	@RequestMapping(value = "/selectDefectFlagFromSome")
	public @ResponseBody ResultBean selectDefectFlagFromSome(@RequestBody Map<String, Object> map) {
		ResultBean selectDefectFlagFromSome = trBasProductConfigService.selectDefectFlagFromSome(map);
		return selectDefectFlagFromSome;
	}
	// 查询产线id通过 tr_bas_pd_pl_route 表
	@RequestMapping(value = "/selectLineByTrBasPdPlRoute/{partId}/{routeId}")
	public @ResponseBody ResultBean selectLineByTrBasPdPlRoute(@PathVariable("partId")Integer partId,@PathVariable("routeId")Integer routeId) {
		ResultBean selectTrBasPdPlRouteByRoutidPartid = trBasPdPlRouteService.selectTrBasPdPlRouteByRoutidPartid(partId, routeId);
		return selectTrBasPdPlRouteByRoutidPartid;
	}
	
	// 是否为合拼工位通过tr_bas_product_config的id查询   是否为拼接的工位（0：否，1：是）
	@RequestMapping(value = "/selectSpliceByid/{val}")
	public @ResponseBody ResultBean selectSpliceByid(@PathVariable Integer val) {
		ResultBean selectSpliceByid = trBasProductConfigService.selectSpliceByid(val);
		return selectSpliceByid;
	}
	
	// 保存是否为合拼工位的信息通过tr_bas_product_config的id查询   是否为拼接的工位（0：否，1：是）
	@RequestMapping(value = "/saveIsSplice/{productConfigId}/{isSplice}")
	public @ResponseBody ResultBean saveIsSplice(@PathVariable Integer productConfigId,@PathVariable Integer isSplice) {
		ResultBean saveIsSplice = trBasProductConfigService.saveIsSplice(productConfigId, isSplice);
	return saveIsSplice;
	}
	
	//配置项更新
	@RequestMapping(value = "/updateConfigurationItem")
	public @ResponseBody ResultBean updateConfigurationItem(@RequestBody ProductConfigAcceptBean productConfigAcceptBean) {
		ResultBean resultBean = new ResultBean(true, "执行错误");
		trBasProductConfigService.updateConfigurationItem(productConfigAcceptBean);
		return resultBean;
	}
	//为true时用来标识是否为首工位
    @RequestMapping(value = "/isShowHeadStation")
	public @ResponseBody ResultBean updateIsShowHeadStation(@RequestBody Map<String, Object> map) {
	    ResultBean resultBean=trBasProductConfigService.updateIsShowHeadStation(map);
		return resultBean;
		}
    
	// 查询产线id通过 tr_bas_pd_pl_route 表
	@RequestMapping(value = "/selectOperationCountByTrBasPdPlRoute")
	public @ResponseBody ResultBean selectOperationCountByTrBasPdPlRoute() {
		ResultBean selectTrBasPdPlRouteByRoutidPartid = trBasPdPlRouteService.selectOperationCountByTrBasPdPlRoute();
		return selectTrBasPdPlRouteByRoutidPartid;
	}
}
